using System;
using System.ComponentModel;
using System.Xml.Serialization;

namespace com.exceptionalsoftware.spacetime.KML
{
	[Serializable()]
    [XmlType(TypeName = "LatLonBoxType")]
    [XmlInclude(typeof(LatLonAltBox))]
	public class LatLonBox : ObjectType
	{
		private double northField, southField, eastField, westField, rotationField;

        public LatLonBox()
            : this(180, -180, 180, -180, 0)
		{
            // Do nothing (extra).
		}

        public LatLonBox(double north, double south, double east, double west)
            : this(north, south, east, west, 0)
        {
            // Do nothing (extra).
        }

        public LatLonBox(double north, double south, double east, double west, double rotation)
        {
            this.North = north;
            this.South = south;
            this.East = east;
            this.West = west;
            this.Rotation = rotation;
        }

        [XmlElement(ElementName = "north", DataType = "double")]
        [DefaultValue(181)]
        public double North
        {
            get { return this.northField; }
            set { this.northField = Coordinate.NormalizeToRepeatingLimits(value, -180, 180); }
        }

        [XmlElement(ElementName = "south", DataType = "double")]
        [DefaultValue(-181)]
        public double South
        {
            get { return this.southField; }
            set { this.southField = Coordinate.NormalizeToRepeatingLimits(value, -180, 180); }
        }

        [XmlElement(ElementName = "east", DataType = "double")]
        [DefaultValue(181)]
        public double East
        {
            get { return this.eastField; }
            set { this.eastField = Coordinate.NormalizeToRepeatingLimits(value, -180, 180); }
        }

        [XmlElement(ElementName = "west", DataType = "double")]
        [DefaultValue(-181)]
        public double West
        {
            get { return this.westField; }
            set { this.westField = Coordinate.NormalizeToRepeatingLimits(value, -180, 180); }
        }

        [XmlElement(ElementName = "rotation", DataType = "double")]
        [DefaultValue(0)]
        public double Rotation
        {
            get { return this.rotationField; }
            set { this.rotationField = Coordinate.NormalizeToRepeatingLimits(value, -180, 180); }
        }
    }
}